/*
 * CommonExceptionHandler.java
 * Copyright 2021 Qunhe Tech, all rights reserved.
 * Qunhe PROPRIETARY/CONFIDENTIAL, any form of usage is subject to approval.
 */

package top.bbman.boot.exception.handler;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 祥霸
 * @version 1.0.0
 */
@Component
@Aspect
@Slf4j
@Order(1000000000)
public class PeaCommonExceptionHandler {

    @Pointcut("@annotation(top.bbman.boot.exception.annotation.PeaCommonException)")
    public void exceptionHandler(){}

//    @Around("exceptionHandler()")
//    public Object execution(ProceedingJoinPoint proceedingJoinPoint){
//        log.info("common-exception-handler");
//        try {
//            return proceedingJoinPoint.proceed();
//        } catch (Throwable t) {
//            log.error("exceptionHandler-controller {}",proceedingJoinPoint, t);
//            return null;
//        }
//    }

    @AfterThrowing(pointcut = "exceptionHandler()",throwing = "e")
    public void execution(JoinPoint joinPoint, Throwable e){
        log.error("exceptionHandler-controller {}", joinPoint, e);
    }
}
